var numComments = numComments || 100,
  avatarSize = avatarSize || 30,
  characters = characters || 90,
  defaultAvatar = defaultAvatar || "http://4.bp.blogspot.com/-F4uzxgXoW1w/UQ42FV-xjgI/AAAAAAAABqA/WO62ahSMgM4/s1600/avatar.jpg",
  moreLinktext = moreLinktext || " More &raquo;",
  showAvatar = (typeof showAvatar === 'undefined') ? true : showAvatar,
  showMorelink = (typeof showMorelink === 'undefined') ? false : showMorelink,
  roundAvatar = (typeof roundAvatar === 'undefined') ? true : roundAvatar;

function tb_recent_comments(tb) {
  var commentsHtml;
  commentsHtml = '<ul class="tb_recent_comments">';
  for (var i = 0; i < numComments; i++) {
    var commentlink, authorName, authorAvatar, avatarClass;
    if (i == tb.feed.entry.length) break;
    commentsHtml += "<li>";
    var entry = tb.feed.entry[i];
    for (var l = 0; l < entry.link.length; l++) {
      if (entry.link[l].rel == 'alternate') {
        commentlink = entry.link[l].href
      }
    }
    for (var a = 0; a < entry.author.length; a++) {
      authorName = entry.author[a].name.$t;
      authorAvatar = entry.author[a].gd$image.src
    }
    if (authorAvatar.indexOf("/s1600/") != -1) {
      authorAvatar = authorAvatar.replace("/s1600/", "/s" + avatarSize + "-c/")
    } else if (authorAvatar.indexOf("/s220/") != -1) {
      authorAvatar = authorAvatar.replace("/s220/", "/s" + avatarSize + "-c/")
    } else if (authorAvatar.indexOf("/s512-c/") != -1 && authorAvatar.indexOf("http:") != 0) {
      authorAvatar = "http:" + authorAvatar.replace("/s512-c/", "/s" + avatarSize + "-c/")
    } else if (authorAvatar.indexOf("blogblog.com/img/b16-rounded.gif") != -1) {
      authorAvatar = "http://2.bp.blogspot.com/-nrBvcJ2o2V8/URB2qXr-cKI/AAAAAAAABrg/4KQuJJwzt78/s" + avatarSize + "/blogger.png"
    } else if (authorAvatar.indexOf("blogblog.com/img/openid16-rounded.gif") != -1) {
      authorAvatar = "http://2.bp.blogspot.com/-9ZLYIeACD8A/URB2xTeD6HI/AAAAAAAABro/WYo0N4Va7cI/s" + avatarSize + "/openid.png"
    } else if (authorAvatar.indexOf("blogblog.com/img/blank.gif") != -1) {
      if (defaultAvatar.indexOf("ilearnzone.blogspot.com") != -1) {
        authorAvatar = defaultAvatar + "&s=" + avatarSize
      } else {
        authorAvatar = defaultAvatar
      }
    } else {
      authorAvatar = authorAvatar
    }
    if (showAvatar == true) {
      if (roundAvatar == true) {
        avatarClass = "avatarRound"
      } else {
        avatarClass = ""
      }
      commentsHtml += "<div class=\"avatarImage " + avatarClass + "\"><img class=\"" + avatarClass + "\" src=\"" + authorAvatar + "\" alt=\"" + authorName + "\" width=\"" + avatarSize + "\" height=\"" + avatarSize + "\"/></div>"
    }
    commentsHtml += "<a href=\"" + commentlink + "\">" + authorName + "</a>";
    var commHTML = entry.content.$t;
    var commBody = commHTML.replace(/(<([^>]+)>)/ig, "");
    if (commBody != "" && commBody.length > characters) {
      commBody = commBody.substring(0, characters);
      commBody += "&hellip;";
      if (showMorelink == true) {
        commBody += "<a href=\"" + commentlink + "\">" + moreLinktext + "</a>"
      }
    } else {
      commBody = commBody
    }
    commentsHtml += "<span>" + commBody + "</span>";
    commentsHtml += "</li>"
  }
  commentsHtml += '</ul>';
  document.write(commentsHtml)
}
